package cn.js.sangu.unitStore.fix;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class FixTemplateNameColumn {

    public static void main(String[] args) {
        // 数据库连接信息
        String url = "jdbc:mysql://sangu.js.cn:3306/unitstore?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8";
        String username = "admin";
        String password = "ls7498801";

        // SQL文件路径
        String sqlFilePath = "d:\\Install\\Project\\Trae\\UtilStore\\store\\unitStore\\src\\main\\resources\\sql\\fix_template_name_column.sql";

        try (Connection conn = DriverManager.getConnection(url, username, password);
             Statement stmt = conn.createStatement();
             BufferedReader br = new BufferedReader(new FileReader(sqlFilePath))) {

            // 读取SQL文件内容
            StringBuilder sql = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null) {
                // 跳过注释行
                if (!line.trim().startsWith("--") && !line.trim().isEmpty()) {
                    sql.append(line);
                }
            }

            // 执行SQL
            stmt.executeUpdate(sql.toString());
            System.out.println("成功修改process_node_template表的template_name列数据类型为VARCHAR");

        } catch (SQLException | IOException e) {
            e.printStackTrace();
            System.err.println("修改列数据类型失败: " + e.getMessage());
        }
    }
}